package com.jsbj.user.controller;


import com.alibaba.fastjson.JSONObject;
import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.page.PageReq;
import com.jsbj.user.entities.SysSystem;
import com.jsbj.user.service.ISysSystemService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-system")
@Api(value = "业务系统管理", tags = "业务系统管理")
//@ApiIgnore
public class SysSystemController extends BaseController {

    @Autowired
    private ISysSystemService sysSystemService;

    @ApiOperation("新增或编辑保存")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true)}
    )
    @PostMapping("saveOrUpdateData")
    public ResultBean<JSONObject> saveOrUpdateData(@RequestBody SysSystem sysSystem){
        return sysSystemService.saveOrUpdateData(sysSystem);
    }

    @ApiOperation("查看详情")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "id（行）", required = true)}
    )
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysSystem.class)})
    @PostMapping("getDetail")
    public ResultBean<SysSystem> getDetail(@RequestParam String id){
        return new ResultBean<>(sysSystemService.getDetail(id));
    }

    @ApiOperation("删除数据")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "id", value = "id（行）", required = true)}
    )
    @PostMapping("deleteData")
    public ResultBean<JSONObject> deleteData(@RequestParam String id){
        return sysSystemService.deleteData(id);
    }

    @ApiOperation("查询列表")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "页码", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页条数", required = true)}
    )
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysSystem.class)})
    @PostMapping("/getListData")
    public ResultBean<PageReq> getListData() {
        return new ResultBean<PageReq>(getPage(sysSystemService.getListData()));
    }

    @ApiOperation("查询管控系统列表（沥青、水稳、水泥）")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "header", dataType = "String", name = "tenantCode", value = "租户id", required = true),
            @ApiImplicitParam(paramType = "header", dataType = "Integer", name = "userId", value = "用户登录id", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "type", value = "类型（1三大系统 2沥青水稳系统）", required = true)}
    )
    @PostMapping("/queryGkSystem")
    public ResultBean<List<Map<String,Object>>> queryGkSystem(@RequestParam Integer type) {
        return new ResultBean<List<Map<String,Object>>>(sysSystemService.queryGkSystem(type));
    }

    @ApiOperation("通过项目编码查询系统列表")
    @GetMapping("/getSystemListByProCode")
    public ResultBean<List<SysSystem>> getSystemListByProCode(@RequestParam String tenantCode) {
        return new ResultBean<List<SysSystem>>(sysSystemService.getSystemListByProCode(tenantCode));
    }

    @ApiOperation("查询所有系统")
    @GetMapping("/getSystemList")
    public ResultBean<List<SysSystem>> getSystemList() {
        return new ResultBean<List<SysSystem>>(sysSystemService.getSystemList());
    }
}

